package roborally.model;

import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * A Class of items. Items have a certain weight. They can share positions with other items.
 * 
 * @author Mathieu REYMOND
 * @author Joren VERSPEURT
 * 
 * @version 2.0
 *
 * @invar ...
 * 		  | canHaveAsWeight(getWeight())
 */
public abstract class Item extends Element {

	/**
	 * Create an item with a given weight.
	 * 
	 * @param weight The given weight
	 * 
	 * @post ...
	 * 		 | if(canHaveAsWeight(weight) )
	 * 		 | then new.getWeight() == weight
	 * 		 | else new.getWeight() == 0
	 */
	protected Item(int weight) {
		
		super();
		this.weight=0;
		
		if(canHaveAsWeight(weight)) {
			this.weight=weight;
		}
	}
	
	/**
	 *  Check if this item can share a position with element other
	 *  
	 *  @param other The element to check
	 *  
	 *  @return ...
	 *  		| result == (this.getClass().isInstance(other) || other.canSharePositionWith(this))
	 */
	@Override
	public boolean canSharePositionWith(Element other) {
		
		boolean result = false;
		
		if(Item.class.isAssignableFrom(other.getClass()) || other.canSharePositionWith(this)) { //items can be on the same position
			
			result = true;
		}
		
		return result;
	}
	
	/**
	 * Check if a this item can have the given weight.
	 * 
	 * @param weight The given weight
	 * 
	 * @return ...
	 * 		   | result == weight >= 0 && weight <= Integer.MAX_VALUE
	 */
	public boolean canHaveAsWeight(double weight) {
		
		return weight >= 0 && weight <= Integer.MAX_VALUE;
	}
	
	/**
	 * Get The item's weight
	 */
	@Basic
	public int getWeight() {
		
		return weight;
	}
	
	/**
	 * The item's weight
	 */
	protected int weight;
	
	/**
	 * A robot can use an item.
	 * 
	 * @param robot The robot that will use this item
	 */
	public abstract void use(Robot robot);
	
	/**
	 * Clone this item
	 */
	@Override
	public abstract Item clone();

}
